<div class="comment-header">
    <span>NHỮNG CHIA SẺ VỀ THƯƠNG HIỆU NÀY</span>
    <div class="dateRange btn">
        THỐNG KÊ
        <!--<i class="fa fa-angle-down"></i>-->
    </div>
    <div class="flatform btn selected">
        BÌNH LUẬN
        <!--<i class="fa fa-angle-down"></i>-->
    </div>
</div>
<div class="comment-body">
    <?php
        for($i = 0; $i < sizeof($comment); $i++){
        ?>
            <div class="comment-item" id="cm_<?php echo $comment[$i]['cmid']; ?>">
                <div class="comment-item-content">
                    <div class="avatar-user">
                        <img src="<?php echo ROOT_URL; ?>upload/avatar/c2.png">
                    </div>
                    <div class="comment-user">
                        <!-- User name-->
                        <div class="comment-user-name">
                            <a href=""><?php echo $comment[$i]['username']; ?></a>
                        </div>
                        <!-- Setting comment-->
                        <div class="comment-user-settings"></div>
                        <!-- Comment content-->
                        <div class="comment-user-text">
                            <?php echo $comment[$i]['comment_content']; ?>
                        </div>
                        <!-- Image or video -->
                        <div class="comment-user-media">
                            <!--<img src="<?php /*echo ROOT_URL; */?>upload/avatar/c2.png">-->
                        </div>
                        <!-- like, number comment, ...-->
                        <div class="comment-user-type">
                            <ul>
                                <li class="comment" cid="<?php echo $comment[$i]['cid']; ?>" cm="<?php echo $comment[$i]['cmid']; ?>">
                                    Trả lời
                                </li>
                                <li>-</li>
                                <li id="like_<?php echo $comment[$i]['cmid']; ?>" class="like" cid="<?php echo $comment[$i]['cid']; ?>" cm="<?php echo $comment[$i]['cmid']; ?>">
                                    <?php
                                        if($comment[$i]['like'] == "true"){
                                            echo '<i class="fa fa-thumbs-up"></i>';
                                        }else{
                                            echo '<i class="fa fa-thumbs-o-up"></i>';
                                        }
                                    ?>
                                    <a href="">
                                        <?php
                                            if($comment[$i]['comment_like'] > 0){
                                                echo $comment[$i]['comment_like'];
                                            }
                                        ?>
                                    </a>
                                </li>
                                <li>-</li>
                                <li class="social-icon">
                                    <i class="fa fa-facebook-square"></i>
                                    <?php echo $comment[$i]['time']; ?>
                                </li>
                            </ul>
                        </div>

                        <div class="comment-user-reply">
                            <?php
                                if(isset($comment[$i]['children'])){
                                    foreach($comment[$i]['children'] as $v){
                                    ?>
                                        <div class="user-reply">
                                            <div class="user-reply-left">
                                                <img src="<?php echo ROOT_URL; ?>upload/avatar/c2.png">
                                            </div>
                                            <div class="user-reply-right">
                                                <div class="user-reply-name">
                                                    <a href=""><?php echo $v['username']; ?></a>
                                                </div>
                                                <div class="user-reply-text">
                                                    <?php echo $v['comment_content']; ?>
                                                </div>
                                                <div class="user-reply-media">
                                                </div>
                                                <div class="user-reply-type">
                                                    <ul>
                                                        <li class="comment" cid="<?php echo $v['cid']; ?>" cm="<?php echo $comment[$i]['cmid']; ?>">
                                                            Trả lời
                                                        </li>
                                                        <li>-</li>
                                                        <li id="like_<?php echo $v['cmid']; ?>" class="like" cid="<?php echo $v['cid']; ?>" cm="<?php echo $v['cmid']; ?>">
                                                            <?php
                                                                if($v['like'] == "true"){
                                                                    echo '<i class="fa fa-thumbs-up"></i>';
                                                                }else{
                                                                    echo '<i class="fa fa-thumbs-o-up"></i>';
                                                                }
                                                            ?>
                                                            <a href="">
                                                                <?php
                                                                    if($v['comment_like'] > 0){
                                                                        echo $v['comment_like'];
                                                                    }
                                                                ?>
                                                            </a>
                                                        </li>
                                                        <li>-</li>
                                                        <li class="social-icon"><!--<i class="fa fa-facebook"></i>--> <?php echo $v['time']; ?></li>
                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                    <?php
                                    }
                                }
                            ?>
                            <!--<div class="user-reply">
                                <div class="user-reply-left">
                                    <img src="<?php /*echo ROOT_URL; */?>upload/avatar/c2.png">
                                </div>
                                <div class="user-reply-right">
                                    <div class="user-reply-name">
                                        <a href="">Đỗ Tuấn</a>
                                    </div>
                                    <div class="user-reply-text">
                                        Buzzy sẽ mời bạn tham gia vào một chiến dịch bằng cách....
                                    </div>
                                    <div class="user-reply-media">
                                    </div>
                                    <div class="user-reply-type">
                                        <ul>
                                            <li>
                                                <i class="fa fa-thumbs-o-up"></i>
                                                <a href="">1</a>
                                            </li>
                                            <li>-</li>
                                            <li>
                                                <i class="fa fa-comment"></i>
                                            </li>
                                            <li>-</li>
                                            <li><i class="fa fa-facebook"></i> 15 minutes ago on Facebook</li>
                                        </ul>
                                    </div>
                                </div>
                            </div>

                            <div class="user-reply">
                                <div class="user-reply-left">
                                    <img src="<?php /*echo ROOT_URL; */?>upload/avatar/c2.png">
                                </div>
                                <div class="user-reply-right">
                                    <div class="user-reply-name">
                                        <a href="">Đỗ Tuấn</a>
                                    </div>
                                    <div class="user-reply-text">
                                        Buzzy sẽ mời bạn tham gia vào một chiến dịch bằng cách....
                                    </div>
                                    <div class="user-reply-media">
                                        <div class="reply-media-thumbnail">
                                            <a title="QUÁN NƯỚNG BBQ" href="" target="_blank">
                                                <div class="reply-media-thumbnail-left">
                                                    <img src="<?php /*echo ROOT_URL; */?>upload/images/campaign.png">
                                                </div>
                                                <div class="reply-media-thumbnail-right">
                                                    <div class="reply-media-thumbnail-right-content">
                                                        <h3>QUÁN NƯỚNG BBQ</h3>
                                                        <p>Thưởng thức các món nướng thịt và hải sản tươi sống tại nhà hàng nước BBQ. Mới khai trương tại 123 Phổ Quang, Tân Bình, HCM</p>
                                                        <p>BUZZY.VN</p>
                                                    </div>
                                                </div>
                                            </a>
                                        </div>
                                    </div>
                                    <div class="user-reply-type">
                                        <ul>
                                            <li>
                                                <i class="fa fa-thumbs-o-up"></i>
                                                <a href="">1</a>
                                            </li>
                                            <li>-</li>
                                            <li>
                                                <i class="fa fa-comment"></i>
                                            </li>
                                            <li>-</li>
                                            <li><i class="fa fa-facebook"></i> 15 minutes ago on Facebook</li>
                                        </ul>
                                    </div>
                                </div>
                            </div>-->

                            <div class="user-reply create-new-comment" style="display: none">
                                <div class="user-reply-left">
                                    <img src="<?php echo ROOT_URL; ?>upload/avatar/c2.png">
                                </div>
                                <div class="user-reply-right">
                                    <div class="user-reply-comment">
                                        <textarea class="wrp-reply-comment" cm="<?php echo $comment[$i]['cmid']; ?>" placeholder="Viết bình luận..."></textarea>
                                        <i class="fa fa-picture-o"></i>
                                        <div class="reply-comment-media-up">
                                            <img src="<?php echo ROOT_URL; ?>upload/avatar/c2.png">
                                            <span class="remove-reply-comment-media-up"><i class="fa fa-times"></i></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        <?php
        }
    ?>
</div>

<script>
    $(function(){
        var reply_comment = $('.wrp-reply-comment');
        reply_comment.autosize();

        var body = $('body');

        body.on('click', '.comment-item .like', function(){
            var comment = $(this).attr('cm');
            var cid = $(this).attr('cid');

            $.ajax({
                type:"POST",
                url: Root_url+"campaign/likeComment",
                dataType: "json",
                data:{'id': comment, 'cid': cid},
                success:(function(data){
                    var like = $('#like_'+comment);
                    if(data.status == "like"){
                        like.find('.fa').removeClass('fa-thumbs-o-up').addClass('fa-thumbs-up');
                        like.find('a').text(data.number);
                    }else if(data.status == "unlike"){
                        like.find('.fa').addClass('fa-thumbs-o-up').removeClass('fa-thumbs-up');
                        like.find('a').text(data.number);
                    }
                })
            });
        });

        body.on('click', '.comment-item .comment', function(){
            var cid = $(this).attr('cid');
            var comment = $(this).attr("cm");

            var cm = $('#cm_'+comment);
            cm.find('.create-new-comment').show();

        });

        reply_comment.keypress(function( event ) {
            if (event.which == 13) {
                var content = $(this).val();
                var id = $(this).attr('cm');
                $.ajax({
                    type:"POST",
                    url: Root_url+"campaign/addChildComment",
                    dataType: "json",
                    data:{'id': id, 'content': content},
                    success:(function(data){
                        if(data.status == "ok"){

                        }
                    })
                });
            }
        });
    });
</script>